﻿using System;
using System.Reflection;
using System.Text;
using System.Collections.Generic;
using System.Linq;
using Ewk.Runtime.Serialization.PositionBased;
using Ewk.Runtime.Serialization.UnitTests.Records;
using Ewk.Runtime.Serialization.UnitTests.Records.PositionBased;
using Microsoft.VisualStudio.TestTools.UnitTesting;

namespace Ewk.Runtime.Serialization.UnitTests.PositionBased
{
    [TestClass]
    public class PositionBasedEnumSerializerTests
    {
        [TestMethod]
        public void PositionBasedEnumSerializer_can_serialize_an_Enum_instance_that_has_a_defined_value()
        {
            var attribute = new PositionBasedDatafieldAttribute(0, 1) {PropertyInfo = GetPropertyInfo()};
            var serializer = new PositionBasedEnumSerializer();
            var result = serializer.Serialize(TestEnum.One, attribute);

            Assert.AreEqual("1", result);
        }

        [TestMethod]
        public void PositionBasedEnumSerializer_can_deserialize_a_string_representation_of_an_Enum_instance_that_has_a_defined_value()
        {
            var attribute = new PositionBasedDatafieldAttribute(0, 1) { PropertyInfo = GetPropertyInfo() };
            var serializer = new PositionBasedEnumSerializer();
            var result = serializer.Deserialize("1", attribute);

            Assert.AreEqual(TestEnum.One, result);
        }

        static PropertyInfo GetPropertyInfo()
        {
            return typeof(PositionBasedTestDatarecordWithEnumField).GetProperty("Field");
        }

        static PropertyInfo GetPropertyInfo(PositionBasedTestDatarecordWithEnumField record)
        {
            return record.GetType().GetProperty("Field");
        }
    }
}
